package tech.xs.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.fastjson.JSONObject;

import tech.xs.entity.Staff;
import tech.xs.service.StaffService;
import tech.xs.service.impl.StaffServiceImpl;
@SuppressWarnings("serial")
@WebServlet("/echo")
public class EchoServlet extends HttpServlet {
	@SuppressWarnings("resource")
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");
		resp.setContentType("application/json;charset=UTF-8");
		ApplicationContext as = new ClassPathXmlApplicationContext("applicationContext.xml");
		StaffService staffSevice = (StaffService) as.getBean("staffServiceImpl");
		PrintWriter io = resp.getWriter();
		Integer id=Integer.parseInt(req.getParameter("id")) ;
		List<Staff> list= staffSevice.getSelectId(id);
		JSONObject json=new JSONObject();
		json.put("data", list);
		io.append(json.toString());
		io.flush();
		io.close();
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}
